using System;
using System.Collections.Generic;

namespace Project3D.my3D.Base
{

    public class myPoint3D
    {
        public double X, Y, Z;

        public myPoint3D() 
        {
            this.X = 0;
            this.Y = 0;
            this.Z = 0;
        }

        public myPoint3D(double x, double y, double z)
        {
            this.X = x;
            this.Y = y;
            this.Z = z;
        }

        public static myVector3D operator -(myPoint3D p1, myPoint3D p2)
        {
            return new myVector3D(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z);
        }

        public static myPoint3D operator +(myPoint3D p1, myVector3D p2)
        {
            return new myPoint3D(p1.X + p2.dX, p1.Y + p2.dY, p1.Z + p2.dZ);
        }

        public static myPoint3D operator *(myPoint3D p, double n)
        {
            return new myPoint3D(p.X * n, p.Y * n, p.Z * n);
        }

        public static myPoint3D operator *(double n, myPoint3D p)
        {
            return p*n;
        }

        public static myPoint3D SumOfPoint(params myPoint3D[] ps)
        {
            myPoint3D newPoint = new myPoint3D();

            foreach (myPoint3D p in ps)
            {
                newPoint.X += p.X;
                newPoint.Y += p.Y;
                newPoint.Z += p.Z;
            }

            return newPoint;
        }

        public static myPoint3D MidPoint(myPoint3D p1, myPoint3D p2)
        {
            return new myPoint3D((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2);
        }

        public static myPoint3D CentroidPoint(myPoint3D[] ps)
        {
            myPoint3D centroid = new myPoint3D();

            foreach (myPoint3D p in ps)
            {
                centroid.X += p.X;
                centroid.Y += p.Y;
                centroid.Z += p.Z;
            }

            centroid.X /= ps.Length;
            centroid.Y /= ps.Length;
            centroid.Z /= ps.Length;

            return centroid;
        }

        public myPoint3D Copy()
        {
            return new myPoint3D(this.X, this.Y, this.Z);
        }
    }

}


